<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="MySQL," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;字符集是一套符号和编码的规则，不论是在oracle数据库还是在mysql数据库，都存在字符集的选择问题。对于数据库来说，字符集又是比较重要的，因为数据库存储的数据大部分都是各种文字，字符集对于数据库的存储、处理性能以及数据迁移都有重要的影响。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;">
<meta name="keywords" content="MySQL">
<meta property="og:type" content="article">
<meta property="og:title" content="mysql字符集调整总结">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/MySQL/20.mysql字符集调整总结/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;字符集是一套符号和编码的规则，不论是在oracle数据库还是在mysql数据库，都存在字符集的选择问题。对于数据库来说，字符集又是比较重要的，因为数据库存储的数据大部分都是各种文字，字符集对于数据库的存储、处理性能以及数据迁移都有重要的影响。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T09:02:01.464Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="mysql字符集调整总结">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;字符集是一套符号和编码的规则，不论是在oracle数据库还是在mysql数据库，都存在字符集的选择问题。对于数据库来说，字符集又是比较重要的，因为数据库存储的数据大部分都是各种文字，字符集对于数据库的存储、处理性能以及数据迁移都有重要的影响。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/MySQL/20.mysql字符集调整总结/"/>





  <title>mysql字符集调整总结 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/MySQL/20.mysql字符集调整总结/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">mysql字符集调整总结</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:06:42+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;字符集是一套符号和编码的规则，不论是在oracle数据库还是在mysql数据库，都存在字符集的选择问题。对于数据库来说，字符集又是比较重要的，因为数据库存储的数据大部分都是各种文字，字符集对于数据库的存储、处理性能以及数据迁移都有重要的影响。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果在数据库创建阶段没有正确选择字符集，那么可能在后期需要更换字符集，而字符集的更换是代价比较高的操作，也存在一定的风险，所以我们建议在应用开始阶段，就按照需求正确的选择合适的字符集，尽量避免后期不必要的调整。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mysql编译安装时，指定字符集的方法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./configure  --with-charset=utf8</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mysql的字符集有4个级别的默认设置：服务器级、数据库级、表级和字段级。分别在不同的地方设置，作用也不相同。</p>
<h2 id="1、服务器字符集设定，在mysql服务启动的时候确定。"><a href="#1、服务器字符集设定，在mysql服务启动的时候确定。" class="headerlink" title="1、服务器字符集设定，在mysql服务启动的时候确定。"></a>1、服务器字符集设定，在mysql服务启动的时候确定。</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;可以在my.cnf中设置：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[mysql]</div><div class="line"><span class="comment">### 默认字符集为utf8</span></div><div class="line">default-character-set=utf8</div><div class="line">[mysqld]</div><div class="line"><span class="comment">### 默认字符集为utf8</span></div><div class="line">default-character-set=utf8</div><div class="line"><span class="comment">### （设定连接mysql数据库时使用utf8编码，以让mysql数据库为utf8运行）</span></div><div class="line">init_connect=<span class="string">'SET NAMES utf8'</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;或者在启动选项中指定：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysqld --default-character-set=utf8</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果没有特别的指定服务器字符集，默认使用latin1(ISO-8859-1的别名)作为服务器字符集。上面三种设置的方式都只指定了字符集，没有去做校对，我们可以用show variables like ‘char%’;命令查询当前服务器的字符<br>集和校对规则。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">mysql&gt;show variables like <span class="string">'char%'</span>;</div><div class="line">   +--------------------------+----------------------------+</div><div class="line"></div><div class="line">　　| Variable_name | Value |</div><div class="line"></div><div class="line">　　+--------------------------+----------------------------+</div><div class="line"></div><div class="line">　　| character_set_client | utf8 |</div><div class="line"></div><div class="line">　　| character_set_connection | utf8 |</div><div class="line"></div><div class="line">　　| character_set_database | utf8 |</div><div class="line"></div><div class="line">　　| character_set_filesystem | binary |</div><div class="line"></div><div class="line">　　| character_set_results | utf8 |</div><div class="line"></div><div class="line">　　| character_set_server | utf8 |</div><div class="line"></div><div class="line">　　| character_set_system | utf8 |</div><div class="line"></div><div class="line">　　| character_sets_dir | /usr/share/mysql/charsets/ |</div><div class="line"></div><div class="line">　　+--------------------------+----------------------------+</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注：如果增加default-character-set=utf8后，MYSQL启动报错。可以用character_set_server=utf8来取代default-character-set=utf8，就能正常启动了。这是因为MYSQL不同版本识别的问题。</p>
<h2 id="2、数据库级"><a href="#2、数据库级" class="headerlink" title="2、数据库级"></a>2、数据库级</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建数据库时指定字符集</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt;CREATE DATABASE my_db default charset utf8 COLLATE utf8_general_ci;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意后面这句话 “COLLATE utf8_general_ci”,大致意思是在排序时根据utf8编码格式来排序<br>如果指定了数据库编码，那么在这个数据库下创建的所有数据表的默认字符集都会是utf8了</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改MYSQL数据库编码，如果是MYSQL数据库编码不正确，可以在MYSQL执行如下命令:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ALTER DATABASE my_db DEFAULT CHARACTER SET utf8;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以上命令就是将MYSQL的my_db数据库的编码设为utf8</p>
<h2 id="3、表级"><a href="#3、表级" class="headerlink" title="3、表级"></a>3、表级</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建表时指定字符集</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt;create table my_table (name varchar(20) not null default <span class="string">''</span>)<span class="built_in">type</span>=myisam default charset utf8;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这句话就是创建一个表,指定默认字符集为utf8</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改MYSQL表的编码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ALTER TABLE my_table DEFAULT CHARACTER SET utf8;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以上命令就是将一个表my_table的编码改为utf8</p>
<h2 id="4、字段级"><a href="#4、字段级" class="headerlink" title="4、字段级"></a>4、字段级</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">alter table <span class="built_in">test</span> add column address varchar(110) after stu_id;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在stu_id后增加一个字段address</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">alter table <span class="built_in">test</span> add id int unsigned not Null auto_increment primary key;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改字段的编码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ALTER TABLE `<span class="built_in">test</span>` CHANGE `name` `name` VARCHAR( 45 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以上命令就是将MYSQL数据库test表中name的字段编码改为utf8</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在命令行下插入汉字时如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">set</span> names utf8;有时候这一句很关键！</div><div class="line">insert into charset values(<span class="string">'王达'</span>);</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意：alter修改的方法不能更新已有记录的字符集，只是对新创建的表和记录生效。对已有记录字符集的调整，需要先将数据导出，经过适当调整后重新导入才可以完全修改编码。</p>
<h2 id="导出导入的字符调整方法"><a href="#导出导入的字符调整方法" class="headerlink" title="导出导入的字符调整方法"></a>导出导入的字符调整方法</h2><h3 id="导出表结构"><a href="#导出表结构" class="headerlink" title="导出表结构"></a>导出表结构</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysqldump -uroot -pmysql --default-character-set=latin1 -d  my_db&gt; createtab.sql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;手工修改createtab.sql表结构定义中的字符集为新的字符集</p>
<h4 id="导出所有记录"><a href="#导出所有记录" class="headerlink" title="导出所有记录"></a>导出所有记录</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysqldump -uroot -pmysql --quick --no-create-info --extended-insert --default-character-set=latin1 --host=localhost  my_db&gt; data.sql</div></pre></td></tr></table></figure>
<h4 id="打开data-sql，将set-names-latin1修改成set-names-utf8"><a href="#打开data-sql，将set-names-latin1修改成set-names-utf8" class="headerlink" title="打开data.sql，将set names latin1修改成set names utf8"></a>打开data.sql，将set names latin1修改成set names utf8</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">:%s/latin1/utf8/g</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;全文替换</p>
<h4 id="使用新的字符集创建新的数据库"><a href="#使用新的字符集创建新的数据库" class="headerlink" title="使用新的字符集创建新的数据库"></a>使用新的字符集创建新的数据库</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">create database  mydata  default charset utf8;</div></pre></td></tr></table></figure>
<h4 id="创建表，执行createtab-sql"><a href="#创建表，执行createtab-sql" class="headerlink" title="创建表，执行createtab.sql"></a>创建表，执行createtab.sql</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql -uroot -pmysql mydata&lt;creattab.sql</div></pre></td></tr></table></figure>
<h4 id="导入数据"><a href="#导入数据" class="headerlink" title="导入数据"></a>导入数据</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql -uroot -pmysql mydata&lt;data.sql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意一点就是目标字符集要大于等于源字符集，否则会丢失一部分不支持的汉字数据。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;附：旧数据升级办法</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以原来的字符集为latin1为例，升级成为utf8的字符集。原来的表: old_table (default charset=latin1)，新表：new_table(default charset=utf8)。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第一步：导出旧数据</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysqldump --default-character-set=latin1 -hlocalhost -uroot -B my_db --tables old_table &gt; old.sql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第二步：转换编码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">iconv -t utf8  -f latin1 -c old.sql &gt; new.sql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在这里，假定原来的数据默认是latin1编码。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第三步：导入</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改old.sql，增加一条sql语句： “SET NAMES utf8;”，保存。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql -hlocalhost -uroot my_db &lt; new.sql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;大功告成！</p>
<h2 id="Mysql-collate规则："><a href="#Mysql-collate规则：" class="headerlink" title="Mysql collate规则："></a>Mysql collate规则：</h2><ul>
<li>*_bin: 表示的是binary case sensitive collation，也就是说是区分大小写的</li>
<li>*_cs: case sensitive collation，区分大小写</li>
<li>*_ci: case insensitive collation，不区分大小写</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/MySQL/" rel="tag"># MySQL</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/MySQL/2. MySQL 5.5 源码安装/" rel="next" title="MySQL 5.5 源码安装">
                <i class="fa fa-chevron-left"></i> MySQL 5.5 源码安装
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/MySQL/21. 同一台MySQL服务器启动多个端口/" rel="prev" title="同一台MySQL服务器启动多个端口">
                同一台MySQL服务器启动多个端口 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、服务器字符集设定，在mysql服务启动的时候确定。"><span class="nav-number">1.</span> <span class="nav-text">1、服务器字符集设定，在mysql服务启动的时候确定。</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、数据库级"><span class="nav-number">2.</span> <span class="nav-text">2、数据库级</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、表级"><span class="nav-number">3.</span> <span class="nav-text">3、表级</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4、字段级"><span class="nav-number">4.</span> <span class="nav-text">4、字段级</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#导出导入的字符调整方法"><span class="nav-number">5.</span> <span class="nav-text">导出导入的字符调整方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#导出表结构"><span class="nav-number">5.1.</span> <span class="nav-text">导出表结构</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#导出所有记录"><span class="nav-number">5.1.1.</span> <span class="nav-text">导出所有记录</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#打开data-sql，将set-names-latin1修改成set-names-utf8"><span class="nav-number">5.1.2.</span> <span class="nav-text">打开data.sql，将set names latin1修改成set names utf8</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用新的字符集创建新的数据库"><span class="nav-number">5.1.3.</span> <span class="nav-text">使用新的字符集创建新的数据库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#创建表，执行createtab-sql"><span class="nav-number">5.1.4.</span> <span class="nav-text">创建表，执行createtab.sql</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#导入数据"><span class="nav-number">5.1.5.</span> <span class="nav-text">导入数据</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Mysql-collate规则："><span class="nav-number">6.</span> <span class="nav-text">Mysql collate规则：</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
